package com.landmesure.communication;

import android.os.Message;

import com.landmesure.bluetoothchat.constant.Constant;
import com.landmesure.bluetoothchat.view.BluetoothFragment;

import java.util.ArrayList;

import static com.landmesure.communication.CommunicationPlatform.SLEEP_TIME;

public class SendMessageThread extends Thread {

    private static ArrayList<String> taskList = new ArrayList<>();

    public static void addTask(String scode) {
        taskList.add(scode);
    }

    public void run() {
        while (true) {
            if (!taskList.isEmpty()) {
                Message msg = new Message();
                msg.obj = taskList.remove(0);;
                msg.what = Constant.SEND_MESSAGE;
                BluetoothFragment.handlerSendMessage(msg);
                try {
                    Thread.sleep(SLEEP_TIME);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
